package coml.jiyun.hp.day02.fragment;


import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import coml.jiyun.hp.day02.R;
import coml.jiyun.hp.day02.adapter.RlvMainAdapter;
import coml.jiyun.hp.day02.bean.Bean;
import coml.jiyun.hp.day02.presenter.CollectionPresenter;
import coml.jiyun.hp.day02.util.LogUtil;
import coml.jiyun.hp.day02.view.CollectionView;

/**
 * A simple {@link Fragment} subclass.
 */
public class CollectionFragment extends BaseLazyLoadFragment implements CollectionView {

    private RecyclerView mRlv;
    private RlvMainAdapter rlvMainAdapter;

    public static CollectionFragment getInstance(){
        CollectionFragment fragment = new CollectionFragment();
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_mainpage;
    }

    @Override
    public void initData() {
//        ((CollectionPresenter)mPresenter).query();
    }

    @Override
    public void initView(View inflate) {
        mRlv = inflate.findViewById(R.id.rlv);

        ArrayList<Bean.ResultsBean> list = new ArrayList<>();
        rlvMainAdapter = new RlvMainAdapter(getContext(), this);
        mRlv.setLayoutManager(new LinearLayoutManager(getContext()));
        mRlv.setAdapter(rlvMainAdapter);

        LogUtil.logd("initView :收藏");
    }

    @Override
    protected Object initPresenter() {
        return new CollectionPresenter(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        LogUtil.logd("destroy:收藏");
    }

    @Override
    public void setData(ArrayList<Bean.ResultsBean> list) {
        rlvMainAdapter.mList.clear();
        rlvMainAdapter.addAll(list);
    }
}